#if !defined(AFX_SINGLETON_H__34E9C593_7B92_4E24_9467_C4AB44663F0F__INCLUDED_)
#define AFX_SINGLETON_H__34E9C593_7B92_4E24_9467_C4AB44663F0F__INCLUDED_

#include <memory>
//using  std::auto_ptr;

template<class T>
class CSingleton
{
private:
    class InstPtr
    {
    public:
        InstPtr() : m_ptr(0) {}
        ~InstPtr() { delete m_ptr; }
        T* Get() { return m_ptr; }
        void Set(T* p)
        {
            if(p!= 0)
            {
                delete m_ptr;
                m_ptr = p;
            }
        }
    private:
        T* m_ptr;
    };

	static std::auto_ptr<T> sm_ptr;

    CSingleton();
    CSingleton(const CSingleton&);
    CSingleton& operator=(const CSingleton&);

public:
    static T* Instance()
    {
        if(sm_ptr.get() == 0)
        {
			std::auto_ptr<T> tmp(new T());
            sm_ptr = tmp;
        }
        return sm_ptr.get();
    }

	
};

#endif // !defined(AFX_SINGLETON_H__34E9C593_7B92_4E24_9467_C4AB44663F0F__INCLUDED_)